package de.ba_rm.java.password.checker.test;

import java.io.File;

import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import de.ba_rm.java.password.checker.logic.config.Rule;

public class JaxbTester {

	/**
	 * @param args
	 * @throws JAXBException 
	 */
	public static void main(String[] args) throws JAXBException {
		new File("test").mkdir();
		final Rule rule = new Rule();
		rule.setMinLength(10);
		rule.setNumCase(5);
		rule.setNumLowerCase(1);
		rule.setNumNumbers(1);
		rule.setNumSpecialBetweenChar(0);
		rule.setNumUpperCase(2);
		rule.setName("TestRichtlinie1");
		
		final Rule rule1 = new Rule();
		rule1.setMinLength(5561);
		rule1.setNumCase(5);
		rule1.setNumLowerCase(1);
		rule1.setNumNumbers(1);
		rule1.setNumSpecialBetweenChar(0);
		rule1.setNumUpperCase(2);
		rule1.setName("TestRichtlinie2");
		
		final Marshaller marshaller = JAXBContext.newInstance(Rule.class).createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		marshaller.marshal(rule, new File("test\\" + rule.getName() + ".xml"));
		marshaller.marshal(rule1, new File("test\\" + rule1.getName() + ".xml"));
		
		final Rule rule2 = JAXB.unmarshal(new File("test\\" + rule.getName() + ".xml"), Rule.class);
		System.out.println(rule2.toString());
	}

}
